package com.jml.spring.springboot.springmvc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

//WebMvcConfigurerAdapter这个接口表示可以配置springmvc的相关的信息，比如视图器，开启注解的配置
//EnableWebMvc表示开启springmvc的功能
//Configuration表示这个类是一个配置文件xml

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.jml.spring.springboot.springmvc.controller")
public class WebConfig extends WebMvcConfigurerAdapter {

	//配置视图器
	@Bean
	public ViewResolver viewResolver() {
		InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
		viewResolver.setPrefix("/WEB-INF/views/");
		viewResolver.setSuffix(".jsp");
		// 可以在JSP页面中通过${}访问beans
		viewResolver.setExposeContextBeansAsAttributes(true);
		return viewResolver;
	}

}
